package app.runner;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import app.htby.utils.KafkaProduceUtils;
import app.kafka.produce.HeartbeatProducer;

/**
 * kafka的心跳发送 ，生产者
 * @author lfy.xys
 * @date 2018年6月1日
 *
 */
@Component
public class KafkaProduceRunner implements CommandLineRunner {
	private static Logger logger = LoggerFactory.getLogger(KafkaProduceRunner.class);

	public void run(String... var1) throws Exception {
		logger.info("This will be execute when the project was started!");
		HeartbeatProducer hp = new HeartbeatProducer();
		
		while(true) {
			Thread.sleep(10000);
			// 发送当前时间
			hp.produce(KafkaProduceUtils.hearbeatTopic, KafkaProduceUtils.hearbeatKey, new Date() + "");
		}
	}
}
